//wifi类型的需求按钮的功能实现，与buttonWifi.vue绑定

import store from "@/store";
import axios from "axios";

function dealCleanRequest(){
    let roomNumber = store.getters.getRoomNumber;

    if(roomNumber!='default'){   
        store.dispatch('sendMessage', {       
            text: '正在请求打扫服务...', 
            receiver: true, 
            request:'default'},
        )
        //访问后端请求服务
        let url="http://localhost:8080/api/clean";
        axios.post(url, {
            roomNumber:roomNumber,
            isClean:true,
        }).then(result=>{
                store.dispatch('sendMessage', {       
                    text: result.data.message,
                    receiver: true, 
                    request:'default'},
                )     
            })
            .catch(err=>{
                console.log(err);
            })
    }else{
        store.dispatch('sendRequest', '打扫服务');
        store.dispatch('sendMessage', {       
            text: '输入房间号', 
            receiver: true, 
            request:'房间号'},
        )   
    }
}

export default{dealCleanRequest}